dojo.require("esri.map");

dojo.addOnLoad(init);

var map,
	currentApplication;

var layersLoaded = 0;

function init() {
	$.ajax({
			type: "GET",
			data: {time: new Date().getTime()},
			url: "admin"});

	$(document).ready(jQueryReady);
}

function initMap() {
	mapLoading = dojo.byId("spinner_map");
	map = createTravellingAnimalsMap();
	map.resize(true);
	map.reposition();
}

function jQueryReady() {
	$("button").button();

	$("#div_control").tabs({select: onTabChange});
	$("#div_toggle").hover(
		function() { $("#div_toggle").fadeTo(500, 1); },
		function() { $("#div_toggle").fadeOut(500, 0.2); }
	);
	$("#a_toggle").click(onToggleDivControl);
	
	$("#div_carte").show("fade", {}, 500);
	
	initMap();	
	
	$("#div_loading_page").hide();
	$("#div_control").show("slide", {direction: "left"}, 500);
	
	// initialiser la premiere app
	currentApplication = 0;
	startAppAddTraveller();
}

function onToggleDivControl() {
	$("#div_control").toggle("slide", {direction: "left"}, 500);
}

function onTabChange(event, ui) {
	switch(currentApplication) {
		case 0:
			stopAppAddTraveller();
			break;
		case 1:
			stopAppFullMap();
			break;
		case 2:
			stopAppPhotos();
			break;
		case 3:
			stopAppReport();
			break;
	}
	
	currentApplication = ui.index;
	
	switch(ui.index) {
		case 0:
			startAppAddTraveller();
			break;
		case 1:
			startAppFullMap();
			break;
		case 2:
			startAppPhotos();
			break;
		case 3:
			startAppReport();
			break;
	}
}

